<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
set_time_limit(0);
$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/SourceSite-utf8/secure";
include("/home/share/www/SourceSite-utf8/secure/config.inc.php");

$arrWeb = explode(",", $_data["AllWeb"]);
//include("AllWeb.inc.php");

//$strBeforeCreateDate = "2008-11-30";//trim($_data["BeforeCreateDate"]);
$strBeforeCreateDate = trim($_data["BeforeCreateDate"]);
$strReportDate0 = trim($_data["ReportDate0"]);
$strReportDate1 = trim($_data["ReportDate1"]);
if($strBeforeCreateDate == "")$strBeforeCreateDate = '1970-01-01';
if($strReportDate0 == "")$strReportDate0 = date("Y-m-d");
if($strReportDate1 == "")$strReportDate1 = date("Y-m-d");
if($strReportDate0 > $strReportDate1){
	$strTmp = $strReportDate0;
	$strReportDate0 = $strReportDate1;
	$strReportDate1 = $strTmp;
}

$strTmp1 = "<tr>
	<td class='web-name'>{No}</td>
	<td class='web-name'>{Web}</td>
	<td class='web-td'>{B1_P1_L0}</td>
	<td class='web-td'>{B1_P1_L1}</td>
	<td class='web-td'>{B1_P1_L2}</td>
	<td class='web-td'>{B1_P0_L0}</td>
	<td class='web-td'>{B1_P0_L1}</td>
	<td class='web-td'>{B1_P0_L2}</td>
	<td class='web-td'>{B0_P1_L0}</td>
	<td class='web-td'>{B0_P1_L1}</td>
	<td class='web-td'>{B0_P1_L2}</td>
	<td class='web-td'>{B0_P0_L0}</td>
	<td class='web-td'>{B0_P0_L1}</td>
	<td class='web-td'>{B0_P0_L2}</td>
</tr>";

$intTotalN = 0;
$intTotalM = 0;
$flTotalR = 0;
$arrDB = array();
$strCon = "";
$intNo = 0;

$_isDBExist = "no";
$_DBSite = "Master";

$strSQL1 = "select ID, isLock, AddDate  from `bet_Member` where MemberGroup = 1";
$strSQL2 = "select MemID  from `bet_BetList` where isPayOff = 0 and (PayupDate between '".$strReportDate0."' and '".$strReportDate1."') group by MemID";
$arrTolUserNo = array();
foreach($arrWeb as $strWeb){
	$arrW = explode("@", $strWeb);
	$strWeb = $arrW[0];
	$_blDBHostM = "";
	include("/home/share/www/".$arrW[1]."/secure/db.inc.php");
	if($_blDBHostM == "")continue;

	$strTmp2 = $strTmp1;
	$strTmp2 = str_replace("{Web}", $strWeb." -- {".$strWeb."} &nbsp;(".$_blDBHostM.")", $strTmp2);
	$intNo++;
	$strTmp2 = str_replace("{No}", $intNo, $strTmp2);

	$arrReportUID = array();
	$RS = @PMA_mysql_query($strSQL2, $$_Conn);
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrReportUID[$Rows -> MemID] = true;
	}

	$arrUserNo = array();
	$RS = @PMA_mysql_query($strSQL1, $$_Conn);
	while($Rows = PMA_mysql_fetch_object($RS)){

		$isReport = ($arrReportUID[$Rows -> ID])?1:0;
		$isBefore = ($Rows -> AddDate <= $strBeforeCreateDate)?1:0;
		$arrUserNo[$Rows -> isLock][$isReport][$isBefore]++;

	} //while($Rows = PMA_mysql_fetch_object($RS)){

	for($intB = 0; $intB <= 1; $intB++){
		for($intP = 0; $intP <= 1; $intP++){
			for($intL = 0; $intL <= 2; $intL++){
				$strTmp2 = str_replace("{B".$intB."_P".$intP."_L".$intL."}", (int)$arrUserNo[$intL][$intP][$intB], $strTmp2);
				$arrTolUserNo[$intL][$intP][$intB] += (int)$arrUserNo[$intL][$intP][$intB];
			}
		}
	}
	$strCon .= $strTmp2;
	@mysql_free_result($RS);
	@mysql_close($$_Conn);
}

$strTmp2 = str_replace("{Web}", "Sum", $strTmp1);
$strTmp2 = str_replace("{No}", "", $strTmp2);
for($intB = 0; $intB <= 1; $intB++){
	for($intP = 0; $intP <= 1; $intP++){
		for($intL = 0; $intL <= 2; $intL++){
			$strTmp2 = str_replace("{B".$intB."_P".$intP."_L".$intL."}", (int)$arrTolUserNo[$intL][$intP][$intB], $strTmp2);
			//$arrTolUserNo[$intL][$intP][$intB] += (int)$arrUserNo[$intL][$intP][$intB];
		}
	}
}
$strCon .= $strTmp2;
?><!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Report </title>
<style>
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #EFFFDF;
}
td {
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #FFFFFF;
	text-align: center;
}
.showTable {
	background-color: #9DBAD8;
	border: 1px solid #056FD8;
}
.web-td {
	text-align: right;
	padding-right: 2px;
}
.web-name {
	text-align: left;
	padding-left: 2px;
}
//-->
</style>
</head>

<body>
<table  border="0" cellspacing="1" cellpadding="0" class="showTable">
<tr>
	<td width="50" rowspan="3">序號</td>
	<td width="150" rowspan="3">網站</td>
	<td colspan="6">開戶日以前 (<?php print $strBeforeCreateDate;?>)</td>
	<td colspan="6">開戶日以後 (<?php print $strBeforeCreateDate;?>)</td>
</tr>
<tr>
	<td colspan="3">有帳務</td>
	<td colspan="3">無帳務</td>
	<td colspan="3">有帳務</td>
	<td colspan="3">無帳務</td>
</tr>
<tr>
	<td width="60">啟用</td>
	<td width="60">停用</td>
	<td width="60">停押</td>
	<td width="60">啟用</td>
	<td width="60">停用</td>
	<td width="60">停押</td>
	<td width="60">啟用</td>
	<td width="60">停用</td>
	<td width="60">停押</td>
	<td width="60">啟用</td>
	<td width="60">停用</td>
	<td width="60">停押</td>
</tr>
<?php print $strCon;?>
</table>
開戶日期界線：<?php print $strBeforeCreateDate;?><br />
現在時間：<?php print date("Y-m-d H:i:s");?><br /><br />
</body>
</html>